import 'package:flutter/material.dart';
import 'package:flutter_demo/chapter10-CustomWidget/turn-box/TurnBox.dart';


void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Animation Widget Demo"),
      ),
      body: TurnBoxWidget(),
    ),
  ));
}

class TurnBoxWidget extends StatefulWidget {
  const TurnBoxWidget({Key? key}) : super(key: key);

  @override
  _TurnBoxWidgetState createState() => _TurnBoxWidgetState();
}

class _TurnBoxWidgetState extends State<TurnBoxWidget> {

  double _turns = .0;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          TurnBox(
            turns: _turns,
            speed: 500,
            child: const Icon(
              Icons.refresh,
              size: 50,
            ),
          ),
          TurnBox(
            turns: _turns,
            speed: 1000,
            child: const Icon(
              Icons.refresh,
              size: 150.0,
            ),
          ),
          ElevatedButton(
            onPressed: () => setState(() => _turns += .2),
            child: const Text("顺时针旋转1/5圈"),
          ),
          ElevatedButton(
            onPressed: () => setState(() => _turns -= .2),
            child: const Text('逆时针旋转1/5圈'),
          ),
        ],
      ),
    );
  }
}
